package com.studio.framework.controller.monitorSystem.service;

import com.studio.framework.controller.monitorSystem.bean.SysUser;
import com.studio.framework.controller.monitorSystem.dto.SysUserDto;
import com.studio.framework.controller.monitorSystem.monitor.MD5Util;
import com.studio.framework.controller.monitorSystem.repository.SysUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author jujh
 * @Date 2018/7/23
 * 用户
 */
@Service
public class SysUserService {

    @Autowired
    private SysUserRepository sysUserRepository;

    public SysUser doLogin(SysUserDto sysUserDto) {
        SysUser sysUser = new SysUser();
        Example<SysUser> example = Example.of(sysUser);
        sysUser.setPassword(MD5Util.sign(sysUserDto.getPassword()));
        sysUser.setPhone(sysUserDto.getPhone());
        List<SysUser> sysUserList = sysUserRepository.findAll(example);
        if (sysUserList != null && !sysUserList.isEmpty()) {
            return sysUserList.get(0);
        } else {
            return null;
        }
    }
}
